/*
 *  Canon.cpp
 *  Rempart
 *
 *
 */

#include "Canon.h"


Canon::Canon(){
	
	this->elementType=MapElement::canon;
	this->canonSprite = new sf::Sprite;
	this->tubeSprite = new sf::Sprite;
	this->setSecured();
	this->resetDefaultSurface();
}

Canon::~Canon(){
	delete this->canonSprite;
	delete this->tubeSprite;
}


void Canon::resetDefaultSurface(){
	this->visible = true;
	this->canonSprite->SetImage(*RessourcesManager::getDefaultBodyCanonSurface());
	this->tubeSprite->SetImage(*RessourcesManager::getDefaultTubeCanonSurface());
	this->tubeSprite->SetPosition(15,15);
	this->tubeSprite->SetCenter(15,15);

}


void Canon::targetCurrentCase() const{
	if (this->secured) {
		double angle = -((atan2(EventManager::getInstance()->getMousePosition().y - this->GetPosition().y-Menu::heigth, EventManager::getInstance()->getMousePosition().x - this->GetPosition().x) *180) /3.14);
		this->tubeSprite->SetRotation(angle);
	}
}

void Canon::Render(sf::RenderTarget& Target) const{
	Target.Draw(*this->canonSprite);
		if (!this->mouseOver) {
			this->targetCurrentCase();
			Target.Draw(*this->tubeSprite);
		}
}



